package springboot1706.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import springboot1706.bean.Goods;
import springboot1706.bean.pagemodel;
import springboot1706.dao.GoodsMapper;

@Service
public class GoodsServiceImpl {
	@Autowired
	private GoodsMapper goodsMapper;
	
	public List<Goods> getGoodById(Goods goods) {
		return goodsMapper.getGoodById(goods);
	}

	public List<Goods> getAll() {
		return goodsMapper.getAll();
	}

//	public List<Goods> getGoodByName(String name,int pageNo, int pageSize) {
//		return goodsMapper.getGoodByName(name,pageNo,pageSize);
//	}

	public int delete(Goods goods) {
		return goodsMapper.delete(goods);
	}

	public int update(Goods goods) {
		return goodsMapper.update(goods);
	}

	public int insert(Goods goods) {
		return goodsMapper.insert(goods);
	}
	public int more(String name) {
		return goodsMapper.more(name);
	}
	public pagemodel<Goods> getGoodByName1(String name,int pageNo, int pageSize) {
		List<Goods> jods = new ArrayList<Goods>();
		int zz=(pageNo - 1)*pageSize;
		Goods se = new Goods();
		se.setName(name);
		se.setPageNo(zz);
		se.setPageSize(pageSize);
		jods  = 	goodsMapper.getGoodByName(se);
		System.out.println("jifadsjflkajl");
		
		pagemodel  pageModel = new pagemodel<Goods>();
		pageModel.setList(jods);
		pageModel.setTotalRecords(goodsMapper.more(name));
		pageModel.setPageSize(pageSize);
		pageModel.setPageNo(pageNo);
		return pageModel;
	}
	
}
